let timeFormat = async function (time) {
  var date = new Date(time);
  let Y = date.getFullYear() + "年";
  let M =
    (date.getMonth() + 1 < 10
      ? "0" + (date.getMonth() + 1)
      : date.getMonth() + 1) + "月";
  let D = date.getDate() + "日";
  let h =
    date.getHours() > 9 ? date.getHours() + "时" : "0" + date.getHours() + "时";
  let m =
    date.getMinutes() > 9
      ? date.getMinutes() + "分"
      : "0" + date.getMinutes() + "分";
  return Y + M + D + h + m;
};

let dateFormat = async function (dateString) {
  const date = new Date(dateString);
  const year = date.getFullYear();
  const month = date.getMonth() + 1;
  const day = date.getDate();

  const formattedDate = `${year}年${month}月${day}日`;
  return formattedDate;
};

/**
 * 判断传入的日期是否在今天以后，如果是则返回ture，不是则返回false
 * @param {*传入的日期} date
 */
let theAfterDay = async function (date) {
  const currentDate = new Date();
  const inputDate = new Date(date);

  // 将日期部分设置为相同，忽略时间部分
  currentDate.setHours(0, 0, 0, 0);
  inputDate.setHours(0, 0, 0, 0);
  console.log(inputDate, currentDate);
  let message;
  if (inputDate > currentDate) {
    message = "传入的日期在当前日期之后";
  } else {
    message = "传入的日期在当前日期之前";
  }
  return message;
};

module.exports = {
  timeFormat,
  dateFormat,
  theAfterDay,
};
